//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.ManagementStudioModels
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using SR = Microsoft.Research.DataLayer;
    using Microsoft.Research.ScientificWorkflow.ManagementStudioModels;
    using System.Windows.Media.Imaging;
    using Microsoft.Research.ScientificWorkflow.TridentUtilities;
    using Microsoft.Research.DataLayer;
    using System.Drawing;
    using System.Collections.ObjectModel;
    using System.IO;
    using System.Windows;
    using System.Collections;
    using Microsoft.Research.ScientificWorkflow.TridentModel;
    using System.Globalization;

    public class WorkflowCatalogViewModel : BaseRegMgrModel
    {
        #region Private Variables

        private bool isDeleted;

        private bool isInteractive;

        private string keywords;

        private string parentBreadcrumb;

        private string iconPath;

        private Image icon;

        private string contact;

        private BitmapImage savedImage;

        private string author;

        private string comments;

        private BitmapImage previewImage;

        private static Dictionary<Image, BitmapImage> imageToBitmapDictionary = new Dictionary<Image, BitmapImage>();

        private static BitmapImage defaultImage;

        private BitmapImage itemImage;

        private string selectedType;

        private const string INTERACTIVETYPE = "Interactive";

        private const string NONINTERACTIVETYPE = "Non Interactive";


        private bool isNotSharedWf = true;

        private string versionLabel;

        private string owner;
        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="WorkFlowCatalogModel"/> class. Initialize the model with information from the 
        /// passed category.
        /// </summary>
        /// <param name="category">The namespace item.</param>
        /// <param name="parent">The parent.</param>
        public WorkflowCatalogViewModel(Activity activity, BaseRegMgrModel parent, bool isLatest, SystemPolicy sysPolicy)
        {
            this.Name = activity.Name;

            // Workflow Name will act as Label as the Label has been binded for Left pane Tree
            this.Label = activity.Name;
            this.Id = (activity as SR.IObject).ID;
            this.Description = activity.Description;
            this.CreateItemIcon();
            this.SavedImage = WorkflowCatalogViewModel.BitmapImageFromSDCtrl(activity.Icon);
            this.Icon = activity.Icon;
            this.CreatedBy = activity.Created.User;
            this.CreatedDate = activity.Created.When;
            this.LastModifiedBy = activity.Updated.User;
            this.LastModifiedTime = activity.Updated.When;
            this.Parent = parent;
            this.Author = activity.Author;
            this.Keywords = activity.Keywords;
            this.Comments = activity.Comments;
            this.Contact = activity.Contacts;
            this.IsInteractive = activity.IsInteractive;
            this.LibraryList = new ObservableCollection<WorkflowAssembly>();
            this.ParameterList = new ObservableCollection<WorkflowParameter>();
            this.SelectedType = this.IsInteractive ? INTERACTIVETYPE : NONINTERACTIVETYPE;

            this.CurrentPermissionSettingsModel = new PermissionSettingsModel(activity as ISecurableObjectInternal, sysPolicy);
            this.VersionLabel = activity.VersionLabel;
            this.Version = activity.Version;
            this.IsLatest = isLatest;
            User ownerUser = activity.Owner as User;
            if (ownerUser != null)
            {
                this.Owner = ownerUser.Name;
            }

            if (!string.IsNullOrEmpty(this.versionLabel) && !IsLatest)
            {
                this.AllowLabelEdit = true;
            }

            // Owner ID of the workflow.
            this.OwnerId = ((IObject)activity.Owner).ID;
            if ((!(TridentAuthentication.LoggedInUser as IObject).ID.Equals(this.OwnerId))
                && TridentAuthentication.LoggedUserRole != UserRole.Admin)
            {
                this.IsNotSharedWF = false;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="WorkFlowCatalogModel"/> class. Initialize the model with information from the 
        /// passed category.
        /// </summary>
        /// <param name="category">The namespace item.</param>
        /// <param name="parent">The parent.</param>
        public WorkflowCatalogViewModel(WorkflowCatalogViewModel model, SystemPolicy sysPolicy)
        {
            this.Name = model.Name;
            this.Label = model.Name;
            this.Id = model.Id;
            this.Description = model.Description;
            this.CreatedBy = model.CreatedBy;
            this.CreatedDate = model.CreatedDate;
            this.LastModifiedBy = model.LastModifiedBy;
            this.LastModifiedTime = model.LastModifiedTime;
            this.LibraryList = model.LibraryList;
            this.ParameterList = model.ParameterList;
            this.Parent = model.Parent;
            this.ParentBreadcrumb = model.ParentBreadcrumb;
            this.Comments = model.Comments;
            this.Contact = model.Contact;
            this.Keywords = model.Keywords;
            this.Author = model.Author;
            this.IconPath = model.IconPath;
            this.ItemIcon = model.ItemIcon;
            this.Icon = model.Icon;
            this.SavedImage = model.SavedImage;
            this.IsInteractive = model.IsInteractive;
            this.SelectedType = model.SelectedType;
            if (model.CurrentPermissionSettingsModel != null && model.CurrentPermissionSettingsModel.SecurableObjectInternal != null)
            {
                this.CurrentPermissionSettingsModel = new PermissionSettingsModel(model.CurrentPermissionSettingsModel.SecurableObjectInternal, sysPolicy);
            }

            this.VersionLabel = model.VersionLabel;
            this.Version = model.Version;
            this.IsLatest = model.IsLatest;
            this.AllowLabelEdit = model.AllowLabelEdit;

            // Owner ID of the workflow.
            this.OwnerId = model.OwnerId;
            this.IsNotSharedWF = model.IsNotSharedWF;
            this.Owner = model.Owner;
        }

        /// <summary>
        /// Creates the item icon.
        /// </summary>
        private void CreateItemIcon()
        {
            try
            {
                Uri uri = new Uri(@"pack://Application:,,,/Microsoft.Research.ScientificWorkflow.TridentUtilities;component/Images/ManagementStudio/workflowIcon.png", UriKind.Absolute);
                this.ItemIcon = new BitmapImage(uri);
                if (this.ItemIcon != null && this.ItemIcon.CanFreeze)
                {
                    this.ItemIcon.Freeze();
                }
            }
            catch (UriFormatException ex)
            {
                TridentErrorHandler.HandleUIException(ex);
            }
            catch (ArgumentException ex)
            {
                TridentErrorHandler.HandleUIException(ex);
            }
            catch (Exception ex)
            {
                TridentErrorHandler.HandleUIException(ex);
            }
        }

        #endregion Constructors

        #region Public Properties

        public ObservableCollection<WorkflowAssembly> LibraryList { get; set; }

        public ObservableCollection<WorkflowParameter> ParameterList { get; set; }

        public string SelectedType
        {
            get
            {
                return this.selectedType;
            }
            set
            {
                this.selectedType = value;
                if (this.selectedType.Equals(INTERACTIVETYPE, StringComparison.OrdinalIgnoreCase))
                {
                    this.IsInteractive = true;
                }
                else
                {
                    this.IsInteractive = false;
                }

                this.RaisePropertyChanged("SelectedType");
            }
        }

        /// <summary>
        ///  A flag indication if the workflow is deleted.
        /// </summary>
        public bool IsDeleted
        {
            get
            {
                return isDeleted;
            }
            set
            {
                isDeleted = value;
                this.RaisePropertyChanged("IsDeleted");
            }
        }

        /// <summary>
        /// The path of the parent bread crumb.
        /// </summary>
        public string ParentBreadcrumb
        {
            get
            {
                return this.parentBreadcrumb;
            }

            set
            {
                this.parentBreadcrumb = value;
                this.RaisePropertyChanged("ParentBreadCrumb");
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is not shared wf.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is not shared wf; otherwise, <c>false</c>.
        /// </value>
        public bool IsNotSharedWF
        {
            get
            {
                return this.isNotSharedWf;
            }
            set
            {
                this.isNotSharedWf = value;
                this.RaisePropertyChanged("IsNotSharedWF");
                this.RaisePropertyChanged("DeleteAllowed");
                this.RaisePropertyChanged("PermissionSettingsAllowed");
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether delete allowed.
        /// </summary>
        /// <value><c>true</c> if delete allowed; otherwise, <c>false</c>.</value>
        public bool DeleteAllowed
        {
            get
            {
                bool validDelete = true;
                if (!this.IsNotSharedWF)
                {
                    validDelete = false;
                }

                return validDelete;
            }
        }

        /// <summary>
        /// Gets a value indicating whether permission settings allowed.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if permission settings allowed; otherwise, <c>false</c>.
        /// </value>
        public bool PermissionSettingsAllowed
        {
            get
            {
                bool validChange = true;
                if (!this.IsNotSharedWF)
                {
                    validChange = false;
                }

                return validChange;
            }
        }

        /// <summary>
        /// Gets or sets the parent model.
        /// </summary>
        public override BaseRegMgrModel Parent
        {
            get
            {
                return base.Parent;
            }
            set
            {
                base.Parent = value;
                if (this.Parent != null)
                {
                    this.ParentBreadcrumb = (null == this.Parent) ? string.Empty : (this.Parent as CategoryViewModel).CategoryBreadcrumb;
                }
            }
        }

        /// <summary>
        /// Gets or sets the keywords.
        /// </summary>
        public string Keywords
        {
            get
            {
                return this.keywords;
            }

            set
            {
                this.keywords = value;
                this.RaisePropertyChanged("Keywords");
            }
        }

        /// <summary>
        /// Gets or sets the keywords.
        /// </summary>
        public string Author
        {
            get
            {
                return this.author;
            }

            set
            {
                this.author = value;
                this.RaisePropertyChanged("Author");
            }
        }

        /// <summary>
        /// Gets or sets the keywords.
        /// </summary>
        public bool IsInteractive
        {
            get
            {
                return this.isInteractive;
            }

            set
            {
                this.isInteractive = value;
                this.RaisePropertyChanged("IsInteractive");
            }
        }

        /// <summary>
        /// Gets or sets the saved image.
        /// </summary>
        /// <value>The saved image.</value>
        public override BitmapImage ItemIcon
        {
            get
            {
                return this.itemImage;
            }
            set
            {
                this.itemImage = value;
            }
        }

        /// <summary>
        /// Gets or sets the keywords.
        /// </summary>
        public string Contact
        {
            get
            {
                return this.contact;
            }

            set
            {
                this.contact = value;
                this.RaisePropertyChanged("Contact");
            }
        }

        /// <summary>
        /// Gets or sets the keywords.
        /// </summary>
        public string Comments
        {
            get
            {
                return this.comments;
            }

            set
            {
                this.comments = value;
                this.RaisePropertyChanged("Comments");
            }
        }

        /// <summary>
        /// The default image.
        /// </summary>
        public static BitmapImage DefaultImage
        {
            get
            {
                if (null == WorkflowCatalogViewModel.defaultImage)
                {
                    WorkflowCatalogViewModel.CreateDefaultImage();
                }

                if (null != WorkflowCatalogViewModel.defaultImage)
                {
                    return WorkflowCatalogViewModel.defaultImage;
                }
                else
                {
                    return null;
                }
            }
        }

        /// <summary>
        /// Gets or sets the icon path.
        /// </summary>
        /// <value>The icon path.</value>
        public string IconPath
        {
            get
            {
                return string.IsNullOrEmpty(this.iconPath) ? "Trident Icon" : this.iconPath;
            }

            set
            {
                string newPath = value;
                string oldPath = this.IconPath;
                if (File.Exists(newPath))
                {
                    try
                    {
                        BitmapImage image = new BitmapImage();
                        image.BeginInit();
                        image.CacheOption = BitmapCacheOption.OnLoad;
                        image.UriSource = new Uri(newPath, UriKind.RelativeOrAbsolute);
                        image.DecodePixelWidth = Constants.BROWSEICONWIDTH;
                        image.EndInit();
                        this.PreviewImage = image;
                        this.iconPath = newPath;
                    }
                    catch (NotSupportedException ex)
                    {
                        TridentErrorHandler.HandleKnownExceptionsInUI(ex,
                            ManagementStudioResourceManager.GetString("InvalidImage"));
                        this.IconPath = oldPath;
                    }
                }

                this.RaisePropertyChanged("IconPath");
            }
        }

        /// <summary>
        /// Gets or sets the icon.
        /// </summary>
        /// <value>The icon.</value>
        public Image Icon
        {
            get { return icon; }
            set
            {
                icon = value;
                this.RaisePropertyChanged("Icon");
            }
        }

        /// <summary>
        /// Gets or sets the preview image.
        /// </summary>
        /// <value>The preview image.</value>
        public BitmapImage PreviewImage
        {
            get
            {
                return this.previewImage != null ? this.previewImage : (BitmapImage)DependencyProperty.UnsetValue;
            }
            set
            {
                this.previewImage = value;
                if (this.previewImage != null && this.previewImage.CanFreeze)
                {
                    this.previewImage.Freeze();
                }

                this.RaisePropertyChanged("PreviewImage");
            }
        }

        /// <summary>
        /// Gets or sets the saved image.
        /// </summary>
        /// <value>The saved image.</value>
        public BitmapImage SavedImage
        {
            get
            {
                return this.savedImage != null ? this.savedImage : WorkflowCatalogViewModel.DefaultImage;
            }
            set
            {
                this.savedImage = value;
                if (this.savedImage != null && this.savedImage.CanFreeze)
                {
                    this.savedImage.Freeze();
                }

                this.RaisePropertyChanged("SavedImage");
                this.RaisePropertyChanged("ItemIcon");
            }
        }

        /// <summary>
        /// Gets a value indicating if there are any input parameters or not.
        /// </summary>
        public bool HasInputParameters
        {
            get
            {
                return this.ParameterList.Count > 0;
            }
        }

        /// <summary>
        /// Gets a value indicating if there are any input parameters or not.
        /// </summary>
        public bool HasNoInputParameters
        {
            get
            {
                return !this.HasInputParameters;
            }
        }

        /// <summary>
        /// Gets a value indicating if there are any related Assemblies or not.
        /// </summary>
        public bool HasAssemblies
        {
            get
            {
                return this.LibraryList.Count > 0;
            }
        }

        /// <summary>
        /// Gets a value indicating if there are any related Assemblies or not.
        /// </summary>
        public bool HasNoAssemblies
        {
            get
            {
                return !this.HasAssemblies;
            }
        }

        /// <summary>
        /// Gets or sets the current permission settings model.
        /// </summary>
        /// <value>The current permission settings model.</value>
        public PermissionSettingsModel CurrentPermissionSettingsModel { get; set; }

        /// <summary>
        /// Gets the display name of the workflow.
        /// </summary>
        public override string Label
        {
            get
            {
                if (!string.IsNullOrEmpty(this.VersionLabel))
                {
                    return string.Format(CultureInfo.CurrentCulture, "{0} ({1})", this.Name, this.VersionLabel);
                }
                else
                {
                    return this.Name;
                }
            }
            set
            {
                base.Label = value;
            }
        }

        /// <summary>
        /// Gets the version label of the workflow.
        /// </summary>
        public string VersionLabel
        {
            get
            {
                return this.versionLabel;
            }
            set
            {
                this.versionLabel = value;
                this.RaisePropertyChanged("VersionLabel");
            }
        }

        /// <summary>
        /// Gets or sets the flag which allows the edit of the versionLabel.
        /// </summary>
        public bool AllowLabelEdit { get; private set; }

        /// <summary>
        /// Gets a flag which specifies whether the worklfow detais are editable.
        /// </summary>
        public bool AreDetailsEditable
        {
            get
            {
                return this.IsLatest;
            }
        }

        /// <summary>
        /// Gets or sets the owner id.
        /// </summary>
        /// <value>The owner id.</value>
        public Guid OwnerId { get; private set; }

        /// <summary>
        /// The owner User name.
        /// </summary>
        public string Owner
        {
            get
            {
                return this.owner;
            }

            set
            {
                this.owner = value;
                this.RaisePropertyChanged("Owner");
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether [additional info loaded].
        /// </summary>
        /// <value>
        /// 	<c>true</c> if [additional info loaded]; otherwise, <c>false</c>.
        /// </value>
        public bool AdditionalInfoLoaded { get; set; }

        #endregion

        #region Methods

        /// <summary>
        /// Overridden tostring method. For automation Ids.
        /// </summary>
        /// <returns>The string representation of the object.</returns>
        public override string ToString()
        {
            if (!string.IsNullOrEmpty(this.Label))
            {
                return this.Label;
            }
            return base.ToString();
        }

        /// <summary>
        /// Creates a clone of the passed model.
        /// </summary>
        /// <param name="workflowViewModel">
        /// Model to clone.
        /// </param>
        /// <returns>
        /// A cloned version.
        /// </returns>
        public static WorkflowCatalogViewModel CreateClone(WorkflowCatalogViewModel workflowViewModel, SystemPolicy sysPolicy)
        {
            WorkflowCatalogViewModel clonedModel = null;
            if (workflowViewModel != null)
            {
                clonedModel = new WorkflowCatalogViewModel(workflowViewModel, sysPolicy);
            }

            return clonedModel;
        }

        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            bool equal = false;
            WorkflowCatalogViewModel equateParam = obj as WorkflowCatalogViewModel;
            if (equateParam != null &&
                WorkflowCatalogViewModel.CheckEquality(equateParam.Name, this.Name) &&
                WorkflowCatalogViewModel.CheckEquality(equateParam.Parent.Id.ToString(), this.Parent.Id.ToString()) &&
                WorkflowCatalogViewModel.CheckEquality(equateParam.Label, this.Label) &&
                WorkflowCatalogViewModel.CheckEquality(equateParam.Keywords, this.Keywords) &&
                WorkflowCatalogViewModel.CheckEquality(equateParam.Description, this.Description) &&
                WorkflowCatalogViewModel.CheckEquality(equateParam.Author, this.Author) &&
                WorkflowCatalogViewModel.CheckEquality(equateParam.Contact, this.Contact) &&
                 WorkflowCatalogViewModel.CheckEquality(equateParam.Comments, this.Comments) &&
                WorkflowCatalogViewModel.CheckEquality(equateParam.IconPath, this.IconPath) &&
                 WorkflowCatalogViewModel.CheckEquality(equateParam.SelectedType, this.SelectedType) &&
                ((equateParam.Parent == null && this.Parent == null) ||
                (equateParam.Parent != null && this.Parent != null && equateParam.Parent.Id.Equals(this.Parent.Id))))
            {
                equal = true;
            }

            return equal;
        }

        /// <summary>
        /// Serves as a hash function for a particular type.
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"/>.
        /// </returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        /// <summary>
        /// Updates the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        public override void Update(BaseRegMgrModel model)
        {
            WorkflowCatalogViewModel wfModel = model as WorkflowCatalogViewModel;
            if (wfModel != null)
            {
                this.Name = wfModel.Name;
                this.Label = wfModel.Label;
                this.Description = wfModel.Description;
                this.CreatedDate = wfModel.CreatedDate;
                this.CreatedBy = wfModel.CreatedBy;
                this.LastModifiedTime = wfModel.LastModifiedTime;
                this.LastModifiedBy = wfModel.LastModifiedBy;
                this.ItemIcon = wfModel.ItemIcon;
                this.SavedImage = wfModel.SavedImage;
                this.Icon = wfModel.Icon;
                this.IconPath = wfModel.IconPath;
                this.Keywords = wfModel.Keywords;
                this.ParentBreadcrumb = wfModel.ParentBreadcrumb;
                this.Author = wfModel.Author;
                this.Comments = wfModel.Comments;
                this.Contact = wfModel.Contact;
                this.IsInteractive = wfModel.IsInteractive;
                if (this.isInteractive)
                {
                    this.SelectedType = INTERACTIVETYPE;
                }
                else
                {
                    this.SelectedType = NONINTERACTIVETYPE;
                }

                this.IsSelected = wfModel.IsSelected;
                this.Owner = wfModel.Owner;
            }
        }

        /// <summary>
        /// Updates the specified saved wf.
        /// </summary>
        /// <param name="savedWf">The saved wf.</param>
        public void Update(Activity activity)
        {
            this.Name = activity.Name;
            // Workflow Name will act as Label as the Label has been binded for Left pane Tree
            this.Label = activity.Name;
            this.Id = (activity as SR.IObject).ID;
            this.Description = activity.Description;
            this.CreateItemIcon();
            this.SavedImage = WorkflowCatalogViewModel.BitmapImageFromSDCtrl(activity.Icon);
            this.Icon = activity.Icon;
            this.CreatedBy = activity.Created.User;
            this.CreatedDate = activity.Created.When;
            this.LastModifiedBy = activity.Updated.User;
            this.LastModifiedTime = activity.Updated.When;
            this.Author = activity.Author;
            this.Keywords = activity.Keywords;
            this.Comments = activity.Comments;
            this.Contact = activity.Contacts;
            this.IsInteractive = activity.IsInteractive;
            User ownerUser = activity.Owner as User;
            if (ownerUser != null)
            {
                this.Owner = ownerUser.Name;
            }

            if (this.isInteractive)
            {
                this.SelectedType = INTERACTIVETYPE;
            }
            else
            {
                this.SelectedType = NONINTERACTIVETYPE;
            }

        }

        private static BitmapImage BitmapImageFromSDCtrl(Image img)
        {
            BitmapImage bitmapImg = null;
            if (img != null)
            {
                if (!WorkflowCatalogViewModel.imageToBitmapDictionary.TryGetValue(img, out bitmapImg))
                {
                    try
                    {
                        using (MemoryStream memStream = new MemoryStream())
                        {
                            img.Save(memStream, System.Drawing.Imaging.ImageFormat.Png);
                            bitmapImg = new BitmapImage();
                            bitmapImg.BeginInit();
                            bitmapImg.CacheOption = BitmapCacheOption.OnLoad;
                            bitmapImg.StreamSource = memStream;
                            bitmapImg.EndInit();
                        }

                        if (null == bitmapImg)
                        {
                            bitmapImg = WorkflowCatalogViewModel.DefaultImage;
                        }
                        else
                        {
                            WorkflowCatalogViewModel.imageToBitmapDictionary[img] = bitmapImg;
                        }
                    }
                    catch (Exception)
                    {
                        bitmapImg = WorkflowCatalogViewModel.DefaultImage;
                    }
                }
            }
            else
            {
                bitmapImg = WorkflowCatalogViewModel.DefaultImage;
            }

            return bitmapImg;
        }

        private static void CreateDefaultImage()
        {
            try
            {
                Uri uri = new Uri(@"pack://Application:,,,/Microsoft.Research.ScientificWorkflow.TridentUtilities;component/Images/ManagementStudio/SelectImage.png", UriKind.Absolute);
                WorkflowCatalogViewModel.defaultImage = new BitmapImage(uri);
                if (WorkflowCatalogViewModel.defaultImage != null && WorkflowCatalogViewModel.defaultImage.CanFreeze)
                {
                    WorkflowCatalogViewModel.defaultImage.Freeze();
                }
            }
            catch (UriFormatException ex)
            {
                TridentErrorHandler.HandleUIException(ex);
            }
            catch (ArgumentException ex)
            {
                TridentErrorHandler.HandleUIException(ex);
            }
            catch (Exception ex)
            {
                TridentErrorHandler.HandleUIException(ex);
            }
        }

        #endregion Methods
    }

    public class WorkflowAssembly
    {
        public WorkflowAssembly(string name, DateTime modifiedDate, string modifiedBy, string version)
        {
            this.Name = name;
            this.ModifiedDate = modifiedDate;
            this.ModifiedBy = modifiedBy;
            this.Version = version;
        }

        public string Name { get; set; }
        public DateTime ModifiedDate { get; set; }
        public string ModifiedBy { get; set; }

        public string Version { get; set; }

        public override string ToString()
        {
            return Name;
        }
    }

    public class WorkflowParameter
    {
        public WorkflowParameter(string name, string dataType, string value)
        {
            this.Name = name;
            this.DataType = dataType;
            this.Value = value;
        }
        public string Name { get; set; }
        public string DataType { get; set; }
        public string Value { get; set; }

        public override string ToString()
        {
            return Name;
        }
    }
}